﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();


        }

        private void button1_Click(object sender, EventArgs e)
        {

            int a, b, result = 0;
            char opr;
            string s1, s2, s3;
          
                try
                {
                    s1 = textBox1.Text;
                    a = Int32.Parse(s1);
                    s2 = textBox2.Text;
                    b = Int32.Parse(s2);
                    s3 = textBox3.Text;
                    opr = Char.Parse(s3);
                    switch (opr)
                    {
                        case '+': result = a + b; break;
                        case '-': result = a - b; break;
                        case '*': result = a * b; break;
                        case '/': result = a / b; break;
                        default:throw new FormatException();

                    }

                }

                catch (System.FormatException)
                {
                    label4.Text = "输入格式不正确"; return;
                }
                catch (DivideByZeroException)
                {
                    label4.Text = "除数不得为0"; return;
                }


                label4.Text = "" + result;

         
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            label4.Text = "结果";
            

        }

    }
}
